package com.hunter.jobs;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.ConsolePipeline;

import com.database.bean.WebsitsJob;

public class WebMagicJob implements Job {
	private static final Logger log = Logger.getLogger(WebMagicJob.class);

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
		WebsitsJob wsj = (WebsitsJob)jobDataMap.get("sitebean");
		log.info("INFO: starting job for "+wsj.getName());
		Spider.create(new WebPageHunter(wsj)).addUrl(wsj.getUrl()).addPipeline(new ConsolePipeline()).run();
		log.info("INFO: end job for "+wsj.getName()+" , waiting for next time.");
	}

}
